package com.hxd.otc.base;

import android.arch.lifecycle.Lifecycle;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.hxd.otc.mvp.base.IBasePresenter;
import com.hxd.otc.mvp.base.IBaseView;
import com.hxd.otc.widget.BlocksToast;
import com.uber.autodispose.AutoDispose;
import com.uber.autodispose.AutoDisposeConverter;
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider;

/**
 * Created by lzy on 2018/11/22 0022.
 * description ${DialogFragment MVP基类}
 */
public abstract class BaseMvpDialogFragment<P extends IBasePresenter> extends BaseDialogFragment implements IBaseView {
    protected P mPresenter;

    public BaseMvpDialogFragment() {
        mPresenter = createPresenter();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public <X> AutoDisposeConverter<X> bindAutoDispose() {
        return AutoDispose.autoDisposable(AndroidLifecycleScopeProvider
                .from(this, Lifecycle.Event.ON_DESTROY));
    }

    protected abstract P createPresenter();

    @Override
    public void showToast(@NonNull String toast) {
        BlocksToast.get().showToast(toast);
    }

    @Override
    public void onShowLoading() {
    }

    @Override
    public void onHideLoading() {
    }

    @Override
    public void onError(int code) {
    }
}
